/**
 * https://ac.nowcoder.com/acm/problem/14122
 */

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,m;
    cin>>n>>m;
    int r[n+1]={0};
    vector<int>v[n+1];
    while(m--){
        int a,b;cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
        r[a]++;
        r[b]++;
    }
    int cn=0;
    while(cn<=10){
        int ma=0,idx=0;
        for(int i=1;i<=n;i++){
            if(r[i]>ma) ma=r[i],idx=i;
        }
        if(idx==0) {cout<<cn<<endl;return ;}
        r[idx]=0;
        for(int i=0;i<v[idx].size();i++){
            int k=v[idx][i];
            r[k]--;
        }
        cn++;
    }
    cout<<"GG"<<endl;
}
 
int main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
}